<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function a(value) {
        console.log("a---", value);
        return "我是aaa";
      }

      function b(value) {
        console.log("b----", value);
        return "我是BBB";
      }
      var arr = [a, a, b, b];

      function func(arr, value) {
        return new Promise((resolve, reject) => {
          if (!arr.length) {
            return;
          }
          const result = arr[0](value);
          arr.shift();
          resolve({
            arr,
            result,
          });
        }).then((res) => {
          func(res.arr, res.result);
        });
      }

      func(arr);

      // 发布订阅模式 

      // react vue 响应式
    </script>
  </body>
</html>
